from Exchange import Exchange1, Exchange2;  # @UnusedImport
from Approach import Approach;
from Loiter import Loiter;
from Meet import Meet;
from Run import Run;
from Walk import Walk;
from Chase1 import Chase1;
from Chase2 import Chase2;
from WaitAndMeet1 import WaitAndMeet1;
from WaitAndMeet2 import WaitAndMeet2;
from ApproachAndMeet import ApproachAndMeet;
from WalkTogether import WalkTogether;
# import math, pylab;

class ActivityMngr(object):
    def __init__(self, actor, actorMngr):
        self.actor = actor;
        self.aActors = actorMngr.aActors;
        self.aActive_Actors = actorMngr.aActive_Actors;
        self.nFrame = -1;
        self.approach = dict();
        self.meet = dict();
        self.loiter = None;
        self.run = None;
        self.walk = None;
        self.chase1 = None;
        self.chase2 = dict();
        self.waitAndMeet1 = None;
        self.waitAndMeet2 = dict();
        self.approachAndMeet = dict();
        self.walkTogether = dict();
        self.aActs = [self.approach, self.meet, self.loiter, 
                      self.run, self.walk, self.chase1, self.chase2, 
                      self.waitAndMeet1, self.waitAndMeet2,
                      self.approachAndMeet, self.walkTogether];
        
    def updateActivities(self, nFrame):
#         if self.actor.nTrackId!=126 or nFrame<4900 or nFrame>5090: return;
#         if self.actor.nTrackId!=19 or nFrame<4886: return;
#         if self.actor.nTrackId!=53: return;
#         if self.actor.nTrackId!=99: return;
#         self.printCurrentActors(nFrame);
#         if self.actor.nTrackId!=99 or nFrame<200 or nFrame>800: return;
#         if self.actor.nTrackId==27 and nFrame>=1050 and nFrame<=1550:
#             nAvgVel = self.actor.getAvgVel_Win(nWin=10);
#             print nFrame, nAvgVel, self.actor.sAction;
#         if self.actor.nTrackId==24:
#             nAvgVel = self.actor.getAvgVel_Win(nWin=10);
#             if nAvgVel<3:
#                 print nFrame, nAvgVel;
#         if self.actor.nTrackId==23 and nFrame<1000: print nFrame, self.actor.aPos, self.actor.getAvgVel_Win(10), self.actor.nHeading;
        self.nFrame = nFrame;
        self.update_Walk(); 
        self.update_WalkTogether();
        self.update_Loiter();
        self.update_Meet();
        self.update_Approach();
        self.update_WaitAndMeet1();
        self.update_WaitAndMeet2();
        self.update_ApproachAndMeet();
#         self.update_Run();
#         self.update_Chase1();
#         self.update_Chase2();
                      
    def check_Active(self): #Called only when this Actor is Missing
        for act in self.aActs:
            if type(act)==dict:
                for nTrackId in act:
                    if act[nTrackId].bStarted: return True;
            elif act!=None and act.bStarted: return True;
            
    def select_Approach_Actors(self): #By Distance Closing within Approach Zone & Person's Field of View
        if self.actor.bMissing: return [];
        aOtherActors = [];
        for otherActor in self.aActive_Actors.values():
#             if otherActor.nTrackId!=81: continue;
            if otherActor==self.actor or otherActor.bMissing: continue;
            if self.actor.aPastPos==[] or otherActor.aPastPos==[]: continue;
#             if not(otherActor.activityMngr.loiter.bStarted): continue; #TEMPORAL CODE [Later make an ApproachToLoiter activity]
            nPastDist = self.actor.points_to_Dist(self.actor.aPastPos, otherActor.aPastPos);
            nNewDist = self.actor.points_to_Dist(self.actor.aPos, otherActor.aPos);
            nDistOtherActor = self.actor.getDist(otherActor);
            bClosingDist = nNewDist<nPastDist;
            bApproachZone = nDistOtherActor<100 and nDistOtherActor>30;
            bNotCreated = not(self.approach.has_key(otherActor.nTrackId));
            if bClosingDist and bApproachZone and bNotCreated and self.actor.checkFOV(otherActor.aPos):
                aOtherActors.append(otherActor);
#                 print self.nFrame, "Person", self.actor.nTrackId, "Approaching to:", otherActor.nTrackId, nDistOtherActor;#"Pos:", otherActor.aPos; #, aActorTracksId;
#                 print self.nFrame, self.actor.nTrackId, otherActor.nTrackId, self.actor.nHeading, pylab.rad2deg(self.actor.nHeading), self.actor.aPastPos, self.actor.aPos, otherActor.aPos;
        return aOtherActors;

    def update_Approach(self):
        #Selection/Creation Phase
        aOtherActors = self.select_Approach_Actors();
        for otherActor in aOtherActors:
            nOtherTrackId = otherActor.nTrackId;
            self.approach[nOtherTrackId] = Approach(self.actor, otherActor);
        for nOtherTrackId in self.approach:
            #Initialization Phase
            otherActor = self.aActors[nOtherTrackId];
            if not(self.approach[nOtherTrackId].bStarted) and self.actor.nAvgVel>0:
#                 if not(otherActor.activityMngr.loiter.bStarted): continue; #TEMPORAL CODE [Later make an ApproachToLoiter activity]
                nPastDist = self.actor.points_to_Dist(self.actor.aPastPos, otherActor.aPastPos);
                nNewDist = self.actor.points_to_Dist(self.actor.aPos, otherActor.aPos);
                nDistOtherActor = self.actor.getDist(otherActor);
                bApproachZone = nDistOtherActor<100 and nDistOtherActor>30;
                bClosingDist = nNewDist<nPastDist;
                if bApproachZone and bClosingDist:
#                     print self.nFrame, "Person", self.actor.nTrackId, "Approaching to:", otherActor.nTrackId, nDistOtherActor;#"Pos:", otherActor.aPos; #, aActorTracksId;
                    self.approach[nOtherTrackId].startAct(self.nFrame);
            #Updating Phase
            bMissing_OtherActor = otherActor.bMissing;
            bNotChase2 = not(self.chase2.has_key(otherActor)) or not(self.chase2[otherActor].bActive);
            if bMissing_OtherActor and bNotChase2: #If the other subject dissapeared, then Kill this Approach (copied from Meet activity)
                self.approach[nOtherTrackId].nProb = 0;
                self.approach[nOtherTrackId].checkBelief_Threshold(self.nFrame);
#                 print "Killing actor", nTrackId;
                continue;
            if self.actor.bMissing: #If the subject dissapeared from screen
                self.approach[nOtherTrackId].update_Missing_Actor(self.nFrame);
            elif self.approach[nOtherTrackId].bStarted: #elif has started
                self.approach[nOtherTrackId].updateAct(self.nFrame);
            
    def printCurrentActors(self, nFrame):
        aActorTracksId = [];
        for actor in self.aActive_Actors.values():
            if actor.bMissing: continue;
            aActorTracksId.append(actor.nTrackId);
        aActorTracksId.sort();
        print nFrame, aActorTracksId;
    
    def update_Loiter(self):
        #Selection/Creation Phase
        if self.loiter==None: 
            self.loiter = Loiter(self.actor);
        #Initialization Phase
        if not(self.loiter.bStarted) and self.actor.getAvgVel_Win(nWin=10)<2: # and self.actor.sAction=="stop": #self.actor.getAvgVel_Win(nWin=3)==0:
            self.loiter.startAct(self.nFrame);
        #Updating Phase            
        if self.actor.bMissing: #If the subject dissapeared from screen
            self.loiter.update_Missing_Actor(self.nFrame);
        elif self.loiter.bStarted: #elif has started
            self.loiter.updateAct(self.nFrame);
    
    def update_WalkTogether(self):
        #Selection/Creation Phase
        aOtherActors = self.select_WalkTogether_Actors();
        for otherActor in aOtherActors:
            nOtherTrackId = otherActor.nTrackId;
            self.walkTogether[nOtherTrackId] = WalkTogether(self.actor, otherActor);
        for nOtherTrackId in self.walkTogether:
            #Initialization Phase
            otherActor = self.aActors[nOtherTrackId];
            if not(self.walkTogether[nOtherTrackId].bStarted):
                bBoth_MedSpeed = self.actor.getAvgVel_Win(nWin=10)>15 and otherActor.getAvgVel_Win(nWin=10)>15;
#                 bBoth_Walk = self.actor.sAction=="walk" and otherActor.sAction=="walk";
                bCloseDist = self.actor.getDist(otherActor)<40;
                otherWT = otherActor.activityMngr.walkTogether;
                bOtherWT = otherWT.has_key(self.actor.nTrackId) and otherWT[self.actor.nTrackId].bStarted;
                if bCloseDist and bBoth_MedSpeed: # and bBoth_Walk: # and not(bOtherWT):
#                     print self.nFrame, "Person", self.actor.nTrackId, "Meeting with:", otherActor.nTrackId;
                    self.walkTogether[nOtherTrackId].startAct(self.nFrame);
            #Updating Phase
            bMissing_OtherActor = otherActor.bMissing;
            if bMissing_OtherActor: #If the other subject dissapeared, then Kill this WalkTogether
                self.walkTogether[nOtherTrackId].nProb = 0;
                self.walkTogether[nOtherTrackId].checkBelief_Threshold(self.nFrame);
                continue;
            if self.actor.bMissing: #If the subject dissapeared from screen
                self.walkTogether[nOtherTrackId].update_Missing_Actor(self.nFrame);
            elif self.walkTogether[nOtherTrackId].bStarted: #elif has started
                self.walkTogether[nOtherTrackId].updateAct(self.nFrame);
                
    def select_WalkTogether_Actors(self):
        if self.actor.bMissing: return [];
        aOtherActors = [];
        for otherActor in self.aActive_Actors.values():
#             if self.actor.nTrackId==23 or otherActor.nTrackId==23: continue;
            if otherActor==self.actor or otherActor.bMissing: continue;
            bBoth_MedSpeed = self.actor.getAvgVel_Win(nWin=10)>15 and otherActor.getAvgVel_Win(nWin=10)>15;
#             bBoth_Walk = self.actor.sAction=="walk" and otherActor.sAction=="walk";
            bSame_Heading = self.actor.getSame_Angle(otherActor)>0.8;
#             print self.nFrame, (self.actor.nTrackId, otherActor.nTrackId);
            bCloseDist = self.actor.getDist(otherActor)<40;
#             bLoiter = self.loiter.bActive;
            bNotCreated = not(self.walkTogether.has_key(otherActor.nTrackId));
#             if bCloseDist and bLoiter and bBoth_LowSpeed and bNotCreated:
#             if bCloseDist and bBoth_MedSpeed and bBoth_Walk and bSame_Heading and bNotCreated:
            if bCloseDist and bBoth_MedSpeed and bSame_Heading and bNotCreated:
                aOtherActors.append(otherActor);
#                 print self.nFrame, "Person", self.actor.nTrackId, "Meeting with:", otherActor.nTrackId, "nAngVel_Act1", self.actor.nAvgVel, "nAngVel_Act2", otherActor.nAvgVel, "nDist", self.actor.getDist(otherActor);
        return aOtherActors;
    
    def update_Meet(self):
        #Selection/Creation Phase
        aOtherActors = self.select_Meet_Actors();
        for otherActor in aOtherActors:
            nOtherTrackId = otherActor.nTrackId;
            self.meet[nOtherTrackId] = Meet(self.actor, otherActor);
        for nOtherTrackId in self.meet:
            #Initialization Phase
            otherActor = self.aActors[nOtherTrackId];
            if not(self.meet[nOtherTrackId].bStarted):
                bBoth_LowSpeed = self.actor.getAvgVel_Win(nWin=10)<10 and otherActor.getAvgVel_Win(nWin=10)<10;
#                 bBoth_Stop = self.actor.sAction=="stop" and otherActor.sAction=="stop";
                bCloseDist = self.actor.getDist(otherActor)<40;
                bLoiter = self.loiter.bActive;                
                if bCloseDist and bLoiter and bBoth_LowSpeed: # and bBoth_Stop:
#                     print self.nFrame, "Person", self.actor.nTrackId, "Meeting with:", otherActor.nTrackId;
                    self.meet[nOtherTrackId].startAct(self.nFrame);
            #Updating Phase
            bMissing_OtherActor = otherActor.bMissing;
            if bMissing_OtherActor: #If the other subject dissapeared, then Kill this Meet
                self.meet[nOtherTrackId].nProb = 0;
                self.meet[nOtherTrackId].checkBelief_Threshold(self.nFrame);
                continue;
            if self.actor.bMissing: #If the subject dissapeared from screen
                self.meet[nOtherTrackId].update_Missing_Actor(self.nFrame);
            elif self.meet[nOtherTrackId].bStarted: #elif has started
                self.meet[nOtherTrackId].updateAct(self.nFrame);
                
    def select_Meet_Actors(self):
        if self.actor.bMissing: return [];
        aOtherActors = [];
        for otherActor in self.aActive_Actors.values():
            if otherActor==self.actor or otherActor.bMissing: continue;
            bBoth_LowSpeed = self.actor.getAvgVel_Win(nWin=10)<10 and otherActor.getAvgVel_Win(nWin=10)<10;
#             bBoth_Stop = self.actor.sAction=="stop" and otherActor.sAction=="stop";
#             print self.nFrame, (self.actor.nTrackId, otherActor.nTrackId);
            bCloseDist = self.actor.getDist(otherActor)<40;
#             bLoiter = self.loiter.bActive;
            bNotCreated = not(self.meet.has_key(otherActor.nTrackId));
#             if bCloseDist and bLoiter and bBoth_LowSpeed and bNotCreated:
#             if bCloseDist and bBoth_LowSpeed and bBoth_Stop and bNotCreated:
            if bCloseDist and bBoth_LowSpeed and bNotCreated:
                aOtherActors.append(otherActor);
#                 print self.nFrame, "Person", self.actor.nTrackId, "Meeting with:", otherActor.nTrackId, "nAngVel_Act1", self.actor.nAvgVel, "nAngVel_Act2", otherActor.nAvgVel, "nDist", self.actor.getDist(otherActor);
        return aOtherActors;
    
    def update_Run(self):
        #Selection/Creation Phase
        if self.run==None: 
            self.run = Run(self.actor);
        #Initialization Phase
        if not(self.run.bStarted) and self.actor.getRun()>0.3:
            self.run.startAct(self.nFrame);
        #Updating Phase            
        if self.actor.bMissing: #If the subject dissapeared from screen
            self.run.update_Missing_Actor(self.nFrame);
        elif self.run.bStarted: #elif has started
            self.run.updateAct(self.nFrame);
    
    def update_Walk(self):
        #Selection/Creation Phase
        if self.walk==None: 
            self.walk = Walk(self.actor);
        #Initialization Phase
        if not(self.walk.bStarted) and (1-self.actor.getStandStill())>0.45:
            self.walk.startAct(self.nFrame);
        #Updating Phase            
        if self.actor.bMissing: #If the subject dissapeared from screen
            self.walk.update_Missing_Actor(self.nFrame);
        elif self.walk.bStarted: #elif has started
            self.walk.updateAct(self.nFrame);
            
    def update_Chase1(self):
        #Selection/Creation Phase
        if self.chase1==None: 
            self.chase1 = Chase1(self.actor);
        #Initialization Phase
        if not(self.chase1.bStarted) and self.run.bActive:
            self.chase1.startAct(self.nFrame);
        #Updating Phase
        if self.actor.bMissing: #If the subject dissapeared from screen
            self.chase1.update_Missing_Actor(self.nFrame);
        elif self.chase1.bStarted: #elif has started
            self.chase1.updateAct(self.nFrame);
            
    def update_Chase2(self):
        #Selection/Creation Phase
        aOtherActors = self.select_Chase2_Actors();
        for otherActor in aOtherActors:
            nTrackId = otherActor.nTrackId;
            self.chase2[nTrackId] = Chase2(self.actor, otherActor);
        for nOtherTrackId in self.chase2:
            #Initialization Phase
            otherActor = self.aActors[nOtherTrackId];
            if not(self.chase2[nOtherTrackId].bStarted):
                otherChase1 = otherActor.activityMngr.chase1;
                bOtherChase1 = otherChase1!=None and otherChase1.bActive;
                if self.run.bActive and bOtherChase1:
#                     print self.nFrame, "Person", self.actor.nTrackId, "Meeting with:", otherActor.nTrackId, otherApproach[nTrackId].nInitRange, otherApproach[nTrackId].nProb;
                    self.chase2[nOtherTrackId].startAct(self.nFrame);
            #Updating Phase
            if self.actor.bMissing: #If the subject dissapeared from screen
                self.chase2[nOtherTrackId].update_Missing_Actor(self.nFrame);
            elif self.chase2[nOtherTrackId].bStarted: #elif has started
                self.chase2[nOtherTrackId].updateAct(self.nFrame);
                
            
    def select_Chase2_Actors(self): #By having Run(thisPerson), Chase1(*,otherPerson) & within Person's Field of View (if still in screen)
        if self.actor.bMissing: return [];
        aOtherActors = [];
        for otherActor in self.aActive_Actors.values():
            if otherActor==self.actor: continue;
            otherChase1 = otherActor.activityMngr.chase1;
            bOtherChase1 = otherChase1!=None and otherChase1.bActive;
            bNotCreated = not(self.chase2.has_key(otherActor.nTrackId));
            bOtherMissing = otherActor.bMissing;
            if self.run.bActive and bNotCreated and bOtherChase1 and (bOtherMissing or self.actor.checkFOV(otherActor.aPos)):
                aOtherActors.append(otherActor);
#                 print self.nFrame, "Person", self.actor.nTrackId, "Approaching to:", otherActor.nTrackId, nDistOtherActor;#"Pos:", otherActor.aPos; #, aActorTracksId;
#                 print self.nFrame, self.actor.nTrackId, otherActor.nTrackId, self.actor.nHeading, pylab.rad2deg(self.actor.nHeading), self.actor.aPastPos, self.actor.aPos, otherActor.aPos;
        return aOtherActors;
    
    def update_WaitAndMeet1(self):
        #Selection/Creation Phase
        if self.waitAndMeet1==None: 
            self.waitAndMeet1 = WaitAndMeet1(self.actor);
        #Initialization Phase
        bNotMeet = True;
#         for nOtherTrackId in self.meet:
#             meet2 = self.aActors[nOtherTrackId].activityMngr.meet;
#             bMeet2_Started = meet2.has_key(self.actor.nTrackId) and meet2[self.actor.nTrackId].bStarted;
#             if self.meet[nOtherTrackId].bStarted or bMeet2_Started:
#                 bNotMeet = False; 
#                 break;
        if not(self.waitAndMeet1.bStarted) and self.loiter.bActive and bNotMeet:
            self.waitAndMeet1.startAct(self.nFrame);
        #Updating Phase            
        if self.actor.bMissing: #If the subject dissapeared from screen
            self.waitAndMeet1.update_Missing_Actor(self.nFrame);
        elif self.waitAndMeet1.bStarted: #elif has started
            self.waitAndMeet1.updateAct(self.nFrame);
    
    def update_WaitAndMeet2(self):
        #Selection/Creation Phase
        aOtherActors = self.select_WaitAndMeet2_Actors();
        for otherActor in aOtherActors:
            nOtherTrackId = otherActor.nTrackId;
            self.waitAndMeet2[nOtherTrackId] = WaitAndMeet2(self.actor, otherActor);
        for nOtherTrackId in self.waitAndMeet2:
            #Initialization Phase
            otherActor = self.aActors[nOtherTrackId];
            if not(self.waitAndMeet2[nOtherTrackId].bStarted):
                nTrackId = self.actor.nTrackId;
                bWaitAndMeet1 = self.waitAndMeet1!=None and self.waitAndMeet1.bActive;
                otherApproach = otherActor.activityMngr.approach;
                bOtherApproach = otherApproach.has_key(nTrackId) and otherApproach[nTrackId].bStarted;
                if not(bWaitAndMeet1 and bOtherApproach): continue;
#                 self.update_Meet();
                bMeet = self.meet.has_key(nOtherTrackId) and self.meet[nOtherTrackId].bStarted;
                if bWaitAndMeet1 and bOtherApproach and bMeet:
#                     print self.nFrame, "Person", self.actor.nTrackId, "Meeting with:", otherActor.nTrackId, otherApproach[nTrackId].nInitRange, otherApproach[nTrackId].nProb;
                    self.waitAndMeet2[nOtherTrackId].startAct(self.nFrame);
            #Updating Phase
            bMissing_OtherActor = otherActor.bMissing;
            if bMissing_OtherActor: #If the other subject dissapeared, then Kill this Meet
                self.waitAndMeet2[nOtherTrackId].nProb = 0;
                self.waitAndMeet2[nOtherTrackId].checkBelief_Threshold(self.nFrame);
                continue;
            if self.actor.bMissing: #If the subject dissapeared from screen
                self.waitAndMeet2[nOtherTrackId].update_Missing_Actor(self.nFrame);
            elif self.waitAndMeet2[nOtherTrackId].bStarted: #elif has started
                self.waitAndMeet2[nOtherTrackId].updateAct(self.nFrame);
                
    def select_WaitAndMeet2_Actors(self):
        if self.actor.bMissing: return [];
        aOtherActors = [];
        for otherActor in self.aActive_Actors.values():
            if otherActor==self.actor or otherActor.bMissing: continue;
            nTrackId = self.actor.nTrackId;
            nOtherTrackId = otherActor.nTrackId;
            bWaitAndMeet1 = self.waitAndMeet1!=None and self.waitAndMeet1.bActive;
            otherApproach = otherActor.activityMngr.approach;
            bOtherApproach = otherApproach.has_key(nTrackId) and otherApproach[nTrackId].bStarted;
            if not(bWaitAndMeet1 and bOtherApproach): continue;
#             self.update_Meet();
            bMeet = self.meet.has_key(nOtherTrackId) and self.meet[nOtherTrackId].bStarted;  
            bNotCreated = not(self.waitAndMeet2.has_key(otherActor.nTrackId)); 
            if bWaitAndMeet1 and bOtherApproach and bMeet and bNotCreated:
                aOtherActors.append(otherActor);
#                 print self.nFrame, "Person", self.actor.nTrackId, "Meeting with:", otherActor.nTrackId, otherApproach[nTrackId].nInitRange, otherApproach[nTrackId].nProb; #, "Pos:", otherActor.aPos;
        return aOtherActors;
    
    def update_ApproachAndMeet(self):
        #Selection/Creation Phase
        aOtherActors = self.select_ApproachAndMeet_Actors();
        for otherActor in aOtherActors:
            nOtherTrackId = otherActor.nTrackId;
            self.approachAndMeet[nOtherTrackId] = ApproachAndMeet(self.actor, otherActor);
        for nOtherTrackId in self.approachAndMeet:
            #Initialization Phase
            otherActor = self.aActors[nOtherTrackId];
            if not(self.approachAndMeet[nOtherTrackId].bStarted):
                nTrackId = self.actor.nTrackId;
                otherApproach = otherActor.activityMngr.approach;
                otherAM = otherActor.activityMngr.approachAndMeet;
                bOtherApproach = otherApproach.has_key(nTrackId) and otherApproach[nTrackId].bStarted;
                bThisApproach = self.approach.has_key(nOtherTrackId) and self.approach[nOtherTrackId].bStarted;
                bOtherAM = otherAM.has_key(nTrackId) and otherAM[nTrackId].bStarted;                
#                 if not(bOtherApproach): continue;
#                 self.update_Meet();
#                 bMeet = self.meet.has_key(nOtherTrackId) and self.meet[nOtherTrackId].bStarted;
                if bThisApproach and bOtherApproach: # and not(bOtherAM):
#                     print self.nFrame, "Person", self.actor.nTrackId, "ApproachMeeting with:", otherActor.nTrackId, otherApproach[nTrackId].nInitRange, otherApproach[nTrackId].nProb;
                    self.approachAndMeet[nOtherTrackId].startAct(self.nFrame);
            #Updating Phase
            bMissing_OtherActor = otherActor.bMissing;
            if bMissing_OtherActor: #If the other subject dissapeared, then Kill this Meet
                self.approachAndMeet[nOtherTrackId].nProb = 0;
                self.approachAndMeet[nOtherTrackId].checkBelief_Threshold(self.nFrame);
                continue;
            if self.actor.bMissing: #If the subject dissapeared from screen
                self.approachAndMeet[nOtherTrackId].update_Missing_Actor(self.nFrame);
            elif self.approachAndMeet[nOtherTrackId].bStarted: #elif has started
                self.approachAndMeet[nOtherTrackId].updateAct(self.nFrame);
                
    def select_ApproachAndMeet_Actors(self):
        if self.actor.bMissing: return [];
        aOtherActors = [];
        for otherActor in self.aActive_Actors.values():
            if otherActor==self.actor or otherActor.bMissing: continue;
            nTrackId, nOtherTrackId = self.actor.nTrackId, otherActor.nTrackId;
            otherApproach = otherActor.activityMngr.approach;
            bOtherApproach = otherApproach.has_key(nTrackId) and otherApproach[nTrackId].bStarted;
            bThisApproach = self.approach.has_key(nOtherTrackId) and self.approach[nOtherTrackId].bStarted;
#             if not(bOtherApproach): continue;
#             self.update_Meet();
#             bMeet = self.meet.has_key(nOtherTrackId) and self.meet[nOtherTrackId].bStarted;  
            bNotCreated = not(self.approachAndMeet.has_key(otherActor.nTrackId));
            bNotLoiter1 = not(otherActor.activityMngr.loiter!=None and otherActor.activityMngr.loiter.bStarted);
            bNotLoiter2 = not(self.loiter!=None and self.loiter.bStarted);
#             bNotWM1 = not((self.waitAndMeet1!=None and self.waitAndMeet1.bStarted) or (otherActor.activityMngr.waitAndMeet1!=None and otherActor.activityMngr.waitAndMeet1.bStarted));
#             bNotLoiter = not(self.loiter.bActive);
#             if bNotLoiter and bOtherApproach and bMeet and bNotCreated:
#             if bNotLoiter and bMeet and bNotCreated:
            if bThisApproach and bOtherApproach and bNotCreated and bNotLoiter1 and bNotLoiter2:
                aOtherActors.append(otherActor);
#                 print self.nFrame, "Person", self.actor.nTrackId, "Meeting with:", otherActor.nTrackId, otherApproach[nTrackId].nInitRange, otherApproach[nTrackId].nProb; #, "Pos:", otherActor.aPos;
        return aOtherActors;
        